package first;

import java.io.*;

public class EditPoBean {
    private String  username;
    private String  password;
    private String  postbox;
    private String  fname;
    private String  sname;
    private String  department;
    private String  object;
    private  String url;

    public EditPoBean() {}

    public String getUsername(){
        return username;
    }

    public void setUsername(String username){
        this.username=username;
    }

    public String getPassword(){
        return password;
    }

    public void setPassword(String password){
        this.password=password;
    }

    public String readFileContent(String username,String url) {
        BufferedReader br = null;
        String line = null;
        StringBuffer bufAll = new StringBuffer(); //保存修改过后的所有内容，不断增加         
        try {
            br = new BufferedReader(new FileReader("Student.txt"));
            String[] massege;
            while ((line = br.readLine()) != null) {
                StringBuffer buf = new StringBuffer();
                //修改内容核心代码
                if (line.startsWith(username)) {
                    massege=line.split(",");
                    buf.append(massege[0]);
                    buf.append(",");
                    buf.append(massege[1]);
                    buf.append(",");
                    buf.append(massege[2]);
                    buf.append(",");
                    buf.append(massege[3]);
                    buf.append(",");
                    buf.append(massege[4]);
                    buf.append(",");
                    buf.append(massege[5]);
                    buf.append(",");
                    buf.append(massege[6]);
                    buf.append(",");
                    buf.append(url);
                    bufAll.append(buf);
                    bufAll.append("\r\n");
                }
                else {
                    bufAll.append(line);
                    bufAll.append("\r\n");
                }

            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (br != null) {
                try {
                    br.close();
                } catch (IOException e) {
                    br = null;
                }
            }
        }
        return bufAll.toString();
    }
    //写回文
    public void writeFile(String content) {
        BufferedWriter bw = null;
        try {
            bw = new BufferedWriter(new FileWriter("student.txt"));
            bw.write(content);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (bw != null) {
                try {
                    bw.close();
                } catch (IOException e) {
                    bw = null;
                }
            }
        }
    }


}
